home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / オンラインウェア / UTIL / TouchMe 1.1.1.sit / touchMe 1.11 Folder / CW9 PP source / source / CTouchMeDialog.cp < prev    next >
Text File  |  1996-08-08  |  14KB  |  539 lines

  1. // ==================================================
  2. //    CTouchMeDialog.cp
  3. //    Copyright (C) 1996 Mizutori Tetsuya, July 4 1996.
  4. // ==================================================
  5. //    All documents are pretty-printed in Geneva 10-point font.
  6.  
  7. #include <LDialogBox.h>
  8. #include <LDragTask.h>
  9. #include <LStdControl.h>
  10. #include <LEditField.h>
  11. #include <LBroadcaster.h>
  12. #include <UDrawingState.h>
  13. #include <UDrawingUtils.h>
  14. #include <UMemoryMgr.h>
  15. #include <UDebugging.h>
  16.  
  17. #include <PP_Messages.h>
  18. #include <UReanimator.h>
  19.  
  20. #include "touchMeConstants.h"
  21. #include "CTouchMeApp.h"
  22. #include "CTouchMeDialog.h"
  23. #include "CRadioButton.h"
  24. #include "CDateEditField.h"
  25. #include "CTouchMePref.h"
  26. #include "UFileInfo.h"
  27. #include "UDateTime.h"
  28.  
  29.  
  30. #define    isButtonOn( xState )        ( (xState) == Button_On )
  31. #define    nButtonValue( xBoolean )    ( (xBoolean) ? Button_On : Button_Off  )
  32.  
  33.  
  34. // --------------------------------------------------
  35. //        ・ CreateTouchMeDialogStream [static]
  36. // --------------------------------------------------
  37.  
  38. CTouchMeDialog *
  39. CTouchMeDialog::CreateTouchMeDialogStream(
  40.     LStream    *inStream )
  41. {
  42.     return new CTouchMeDialog( inStream );
  43. }
  44.  
  45.  
  46. // --------------------------------------------------
  47. //        ・ CTouchMeDialog(LStream *)
  48. // --------------------------------------------------
  49.  
  50. CTouchMeDialog::CTouchMeDialog(
  51.     LStream *inStream )
  52.         : LDialogBox( inStream ),
  53.         LDragAndDrop( UQDGlobals::GetCurrentPort(), this )
  54. {
  55.     mModifier = false;
  56.     mHilitePaneID = kNoPaneID;
  57. }
  58.  
  59.  
  60. // --------------------------------------------------
  61. //        ・ ~CTouchMeDialog
  62. // --------------------------------------------------
  63.  
  64. CTouchMeDialog::~CTouchMeDialog()
  65. {
  66. }
  67.  
  68.  
  69. // --------------------------------------------------
  70. //        ・ FinishCreateSelf
  71. // --------------------------------------------------
  72.  
  73. void
  74. CTouchMeDialog::FinishCreateSelf()
  75. {
  76.     LDialogBox::FinishCreateSelf();
  77.  
  78.     UReanimator::LinkListenerToControls( this, this, rRidL_TouchMeDialog );
  79.  
  80.     // This DialogBox listens to myself the messages from Drag & Drop operations, etc.
  81.     this->AddListener( this );
  82.  
  83.     // Add listeners of CRadioButtons to broadcaster of LStdCheckBox.
  84.     // When the LStdCheckBox has changed, then change message will be sent to CRadioButtons.
  85.     LStdCheckBox    *theCheckBox;
  86.     CRadioButton    *theRadio;
  87.  
  88.     theCheckBox = (LStdCheckBox *) FindPaneByID( kTmeD_CrCheckbox );
  89.     for ( long i = touchFlag_Current; i < touchFlag_END; i++ ) {
  90.         theRadio = (CRadioButton *) FindPaneByID( kTmeD_CrButtonCurrent + i );
  91.         theCheckBox->AddListener( theRadio );
  92.     }
  93.  
  94.     theCheckBox = (LStdCheckBox *) FindPaneByID( kTmeD_MdCheckbox );
  95.     for ( long i = touchFlag_Current; i < touchFlag_END; i++ ) {
  96.         theRadio = (CRadioButton *) FindPaneByID( kTmeD_MdButtonCurrent + i );
  97.         theCheckBox->AddListener( theRadio );
  98.     }
  99.  
  100.  
  101. //    This time, we do not apply Broadcast/Listener method to my EditField objects.
  102. #ifdef COMMENT
  103. /*    
  104.     PaneIDT    theDateEditFieldList[8] = {
  105.                 kTmeD_CrTextEditDate, kTmeD_CrTextEditTime,
  106.                 kTmeD_MdTextEditDate, kTmeD_MdTextEditTime,
  107.                 kNoPaneID };
  108.     PaneIDT    iPaneID, iPaneID2;
  109.  
  110.     CDateEditField    *theEditField, *theEditField2;
  111.     for ( long i=0; (iPaneID=theDateEditFieldList[i]) != kNoPaneID; i++ ) {
  112.         theEditField = (CDateEditField *) FindPaneByID( iPaneID );
  113.     for ( long j=0; (iPaneID2=theDateEditFieldList[j]) != kNoPaneID; j++ ) {
  114.         theEditField2 = (CDateEditField *) FindPaneByID( iPaneID2 );
  115.         theEditField->AddListener( theEditField2 );
  116.     }
  117.     }
  118. */
  119. #endif // COMMENT
  120.  
  121. }
  122.  
  123.  
  124. // --------------------------------------------------
  125. //        ・ DrawSelf
  126. // --------------------------------------------------
  127. // Draw my additional custom figures in the dialog window.
  128. // This procedure erases the 2-pixel width region near the bound.
  129. // The reason is that the 2-pixel region may not be hilited properly
  130. // during a drag & drop because my window is colored at background.
  131.  
  132. void
  133. CTouchMeDialog::DrawSelf()
  134. {
  135.     StColorPenState    theCurrentState;
  136. //    LDialogBox::DrawSelf();    
  137.     StColorPenState::Normalize();
  138.  
  139.     RgnHandle    theRgnH = ::NewRgn();
  140.     RgnHandle    theInRgnH = ::NewRgn();
  141.  
  142.     Rect        theRect;
  143.     CalcLocalFrameRect( theRect );
  144.     ::RectRgn( theRgnH, &theRect );
  145.     ::InsetRect( &theRect, 2, 2);
  146.     ::RectRgn( theInRgnH, &theRect );
  147.     ::DiffRgn( theRgnH, theInRgnH, theRgnH );
  148.  
  149.     ::EraseRgn( theRgnH );
  150.  
  151.     ::DisposeRgn( theRgnH );
  152.     ::DisposeRgn( theInRgnH );
  153. }
  154.  
  155.  
  156. // --------------------------------------------------
  157. //        ・ AttemptClose
  158. // --------------------------------------------------
  159. // Quit program like as "Cancel" button if "Close Box" was selected.
  160.  
  161. void
  162. CTouchMeDialog::AttemptClose()
  163. {
  164.     //LDialogBox::AttemptClose();
  165.  
  166.     BroadcastMessage( msg_TmeD_ButtonCencel, (void *) nil );
  167. }
  168.  
  169.  
  170. // --------------------------------------------------
  171. //        ・ FindCommandStatus
  172. // --------------------------------------------------
  173.  
  174. void
  175. CTouchMeDialog::FindCommandStatus(
  176.     CommandT    inCommand,
  177.     Boolean&    outEnabled,
  178.     Boolean&    outUsesMark,
  179.     Char16&    outMark,
  180.     Str255    outName )
  181. {    
  182.     switch (inCommand) {
  183.         case cmd_About:
  184.         case cmd_Open:
  185.         case cmd_Save:
  186.         case cmd_Quit:
  187.             outEnabled = true;
  188.             break;
  189.         default:
  190.             outEnabled = false;
  191.             break;
  192.     }
  193. }
  194.  
  195.  
  196.  
  197. // --------------------------------------------------
  198. //        ・ ListenToMessage
  199. // --------------------------------------------------
  200.  
  201. void
  202. CTouchMeDialog::ListenToMessage(
  203.     MessageT    inMessage,
  204.     void        *ioParam )
  205. {
  206.     switch ( inMessage ) {
  207.  
  208.         case msg_TmeD_ButtonOK:
  209.         {
  210.             // Store the preference data to Prefs file.
  211.             ProcessCommand( cmd_SavePrefs, ioParam );
  212.             LDialogBox::ListenToMessage( inMessage, ioParam );
  213.         }
  214.         break;
  215.  
  216.         case msg_TmeD_ButtonCencel:
  217.         {
  218.             // Discard the preference data.
  219.             ProcessCommand( cmd_SavePrefsWFrame, ioParam );
  220.             LDialogBox::ListenToMessage( inMessage, ioParam );
  221.         }
  222.         break;
  223.  
  224.         case msg_TmeD_ButtonHelp:
  225.         {
  226.             // Show the help window.
  227.             ProcessCommand( cmd_Open_HelpWindow, ioParam );
  228.         }
  229.         break;
  230.  
  231.         case msg_TmeD_Title:
  232.         {
  233.             // Show the About window.
  234.             // But this does not work because 'Title' pane is not enabled now.
  235.             ProcessCommand( cmd_About, ioParam );
  236.         }
  237.         break;
  238.  
  239.         case msg_TmeD_CrButtonNow:
  240.         {
  241.             // Set up creation date time EditFields to the current date time.
  242.             unsigned long    theDateTimeSecs;
  243.             ::GetDateTime( &theDateTimeSecs );
  244.  
  245.             SetEdifFieldDateTime( kTmeD_CrTextEditDate, theDateTimeSecs );
  246.             SetEdifFieldDateTime( kTmeD_CrTextEditTime, theDateTimeSecs );
  247.  
  248.             if ( GetValueForPaneID( kTmeD_ButtonSync ) == Button_On ) {
  249.             SetEdifFieldDateTime( kTmeD_MdTextEditDate, theDateTimeSecs );
  250.             SetEdifFieldDateTime( kTmeD_MdTextEditTime, theDateTimeSecs );
  251.             }
  252.         }
  253.         break;
  254.  
  255.         case msg_TmeD_MdButtonNow:
  256.         {
  257.             // Set up modification date time EditFields to the current date time.
  258.             unsigned long    theDateTimeSecs;
  259.             ::GetDateTime( &theDateTimeSecs );
  260.  
  261.             SetEdifFieldDateTime( kTmeD_MdTextEditDate, theDateTimeSecs );
  262.             SetEdifFieldDateTime( kTmeD_MdTextEditTime, theDateTimeSecs );
  263.  
  264.             if ( GetValueForPaneID( kTmeD_ButtonSync ) == Button_On ) {
  265.             SetEdifFieldDateTime( kTmeD_CrTextEditDate, theDateTimeSecs );
  266.             SetEdifFieldDateTime( kTmeD_CrTextEditTime, theDateTimeSecs );
  267.             }
  268.         }
  269.         break;
  270.  
  271.         case msg_TmeD_DroppedFile:
  272.         {
  273.             // Setup date time EditFields according to the date time stamp of the dropped file.
  274.             // Parameter: FSSpec *ioParam
  275.             FSSpec        * theFSSpec = (FSSpec *) ioParam;
  276.             unsigned long    theCrDateTime = 0, theMdDateTime = 0;
  277.             UFileInfo::GetFSSpecDateTime( *theFSSpec, theCrDateTime, theMdDateTime );
  278.  
  279.             SetEdifFieldDateTime( kTmeD_CrTextEditDate, theCrDateTime );
  280.             SetEdifFieldDateTime( kTmeD_CrTextEditTime, theCrDateTime );
  281.  
  282.             SetEdifFieldDateTime( kTmeD_MdTextEditDate, theMdDateTime );
  283.             SetEdifFieldDateTime( kTmeD_MdTextEditTime, theMdDateTime );
  284.         }
  285.         break;
  286.  
  287.         case msg_TmeD_DroppedFileCrDate:
  288.         case msg_TmeD_DroppedFileCrTime:
  289.         case msg_TmeD_DroppedFileMdDate:
  290.         case msg_TmeD_DroppedFileMdTime:
  291.         {
  292.             // Setup date time EditFields separately according to the dropped file.
  293.             FSSpec        * theFSSpec = (FSSpec *) ioParam;
  294.             unsigned long    theCrDateTime = 0, theMdDateTime = 0;
  295.             UFileInfo::GetFSSpecDateTime( *theFSSpec, theCrDateTime, theMdDateTime );
  296.  
  297.             switch ( inMessage ) {
  298.                 case msg_TmeD_DroppedFileCrDate:
  299.                     SetEdifFieldDateTime( kTmeD_CrTextEditDate, theCrDateTime ); break;
  300.                 case msg_TmeD_DroppedFileCrTime:
  301.                     SetEdifFieldDateTime( kTmeD_CrTextEditTime, theCrDateTime ); break;
  302.                 case msg_TmeD_DroppedFileMdDate:
  303.                     SetEdifFieldDateTime( kTmeD_MdTextEditDate, theMdDateTime ); break;
  304.                 case msg_TmeD_DroppedFileMdTime:
  305.                     SetEdifFieldDateTime( kTmeD_MdTextEditTime, theMdDateTime ); break;
  306.             }
  307.         }
  308.         break;
  309.  
  310.         case msg_TmeD_CrCheckbox:
  311.         case msg_TmeD_MdCheckbox:
  312.         {
  313.             // Do nothing here.
  314.         }
  315.         break;
  316.  
  317.         case msg_TmeD_CrButtonCurrent:
  318.         case msg_TmeD_CrButtonDirect:
  319.         case msg_TmeD_CrButtonFirst:
  320.         case msg_TmeD_CrButtonSecond:
  321.         {    
  322.             long k =  inMessage - msg_TmeD_CrButtonCurrent;
  323.             if ( GetValueForPaneID( kTmeD_ButtonSync ) == Button_On )
  324.             if ( GetValueForPaneID( kTmeD_CrButtonCurrent + k ) == Button_On )
  325.                 SetValueForPaneID( kTmeD_MdButtonCurrent + k, Button_On );
  326.         }
  327.         break;
  328.  
  329.         case msg_TmeD_MdButtonCurrent:
  330.         case msg_TmeD_MdButtonDirect:
  331.         case msg_TmeD_MdButtonFirst:
  332.         case msg_TmeD_MdButtonSecond:
  333.         {    
  334.             long k =  inMessage - msg_TmeD_MdButtonCurrent;
  335.             if ( GetValueForPaneID( kTmeD_ButtonSync ) == Button_On )
  336.             if ( GetValueForPaneID( kTmeD_MdButtonCurrent + k ) == Button_On )
  337.                 SetValueForPaneID( kTmeD_CrButtonCurrent + k, Button_On );
  338.         }
  339.         break;
  340.  
  341.         default:
  342.         {
  343.             LDialogBox::ListenToMessage( inMessage, ioParam );
  344.             break;
  345.         }
  346.  
  347.     }
  348. }
  349.  
  350.  
  351. // ==================================================
  352. //    Seup Dialog
  353. // ==================================================
  354.  
  355. // --------------------------------------------------
  356. //        ・ GetGlobalFrameRect
  357. // --------------------------------------------------
  358.  
  359. void
  360. CTouchMeDialog::GetGlobalFrameRect(
  361.     Rect &    outRect )
  362. {
  363.     CalcPortFrameRect( outRect );
  364.     PortToGlobalPoint( topLeft( outRect ) );
  365.     PortToGlobalPoint( botRight( outRect ) );
  366. }
  367.  
  368.  
  369. // --------------------------------------------------
  370. //        ・ MoveDialog
  371. // --------------------------------------------------
  372.  
  373. void
  374. CTouchMeDialog::MoveDialog(
  375.     CTouchMePref    &inPref )
  376. {
  377.     Rect        theWindowRect;
  378.     inPref.GetWindowRect( theWindowRect );
  379.  
  380.     if ( ! ::EmptyRect( &theWindowRect ) ) {
  381.         DoSetPosition( topLeft( theWindowRect ));
  382.     }
  383. }
  384.  
  385.  
  386. // --------------------------------------------------
  387. //        ・ SetupDialog
  388. // --------------------------------------------------
  389.  
  390. void
  391. CTouchMeDialog::SetupDialog(
  392.     CTouchMePref    &inPref )
  393. {
  394.     Rect        theWindowRect;
  395.     inPref.GetWindowRect( theWindowRect );
  396.  
  397.     if ( ! ::EmptyRect( &theWindowRect ) ) {
  398.         DoSetPosition( topLeft( theWindowRect ));
  399.     }
  400.  
  401.     SetValueForPaneID( kTmeD_CrCheckbox,
  402.             nButtonValue( inPref.GetEnabled( touchType_CreationDate ) ) );
  403.  
  404.     SetValueForPaneID( kTmeD_MdCheckbox, 
  405.             nButtonValue( inPref.GetEnabled( touchType_ModificationDate ) ) );
  406.  
  407.     SetValueForPaneID( kTmeD_ButtonSync, 
  408.             nButtonValue( inPref.GetSync() ) );
  409.  
  410.     // Because we're about to set the value for controls
  411.     // we're listening to we'll turn off listening temporarily.
  412.     // Otherwise we'll get in a tug-of-war
  413.     // as the controls broadcast their changing values.
  414.     StopListening();
  415.  
  416.     for ( long i = touchFlag_Current; i < touchFlag_END; i++ ) {
  417.         SetValueForPaneID( kTmeD_CrButtonCurrent + i, 
  418.             nButtonValue( inPref.GetFlag( touchType_CreationDate, (ETouchFlag) i ) ) );
  419.     }
  420.  
  421.     for ( long i = touchFlag_Current; i < touchFlag_END; i++ ) {
  422.         SetValueForPaneID( kTmeD_MdButtonCurrent + i, 
  423.             nButtonValue( inPref.GetFlag( touchType_ModificationDate, (ETouchFlag) i ) ) );
  424.     }
  425.  
  426.     // Start listening again.            
  427.     StartListening();
  428.  
  429.  
  430.     Str255    str;
  431.  
  432.     inPref.GetDateString( touchType_CreationDate, str );
  433.     SetEdifFieldText( kTmeD_CrTextEditDate, str);
  434.  
  435.     inPref.GetTimeString( touchType_CreationDate, str );
  436.     SetEdifFieldText( kTmeD_CrTextEditTime, str);
  437.  
  438.  
  439.     inPref.GetDateString( touchType_ModificationDate, str );
  440.     SetEdifFieldText( kTmeD_MdTextEditDate, str);
  441.  
  442.     inPref.GetTimeString( touchType_ModificationDate, str );
  443.     SetEdifFieldText( kTmeD_MdTextEditTime, str);
  444. }
  445.  
  446.  
  447. // --------------------------------------------------
  448. //        ・ InspectDialog
  449. // --------------------------------------------------
  450.  
  451. void
  452. CTouchMeDialog::InspectDialog(
  453.     CTouchMePref    &outPref )
  454. {
  455.     Rect        theWindowRect;
  456.     GetGlobalFrameRect( theWindowRect );
  457.     outPref.SetWindowRect( theWindowRect );
  458.  
  459.     outPref.SetEnabled( touchType_CreationDate,
  460.                 isButtonOn( GetValueForPaneID( kTmeD_CrCheckbox ) ) );
  461.  
  462.     outPref.SetEnabled( touchType_ModificationDate,
  463.                 isButtonOn( GetValueForPaneID( kTmeD_MdCheckbox ) ) );
  464.  
  465.     outPref.SetSync( isButtonOn( GetValueForPaneID( kTmeD_ButtonSync ) ) );
  466.  
  467.     for ( long i = touchFlag_Current; i < touchFlag_END; i++ ) {
  468.         outPref.SetFlag( touchType_CreationDate, (ETouchFlag) i,
  469.                 isButtonOn( GetValueForPaneID( kTmeD_CrButtonCurrent + i ) ) );
  470.     }
  471.  
  472.     for ( long i = touchFlag_Current; i < touchFlag_END; i++ ) {
  473.         outPref.SetFlag( touchType_ModificationDate, (ETouchFlag) i,
  474.                 isButtonOn( GetValueForPaneID( kTmeD_MdButtonCurrent + i ) ) );
  475.     }
  476.  
  477.  
  478.     Str255    str;
  479.  
  480.     GetEdifFieldText( kTmeD_CrTextEditDate, str );
  481.     outPref.SetDateString( touchType_CreationDate, str );
  482.  
  483.     GetEdifFieldText( kTmeD_CrTextEditTime, str);
  484.     outPref.SetTimeString( touchType_CreationDate, str );
  485.  
  486.     GetEdifFieldText( kTmeD_MdTextEditDate, str);
  487.     outPref.SetDateString( touchType_ModificationDate, str );
  488.  
  489.     GetEdifFieldText( kTmeD_MdTextEditTime, str);
  490.     outPref.SetTimeString( touchType_ModificationDate, str );
  491. }
  492.  
  493.  
  494.  
  495. // ==================================================
  496. //    Common functions
  497. // ==================================================
  498.  
  499. // --------------------------------------------------
  500. //        ・ SetEdifFieldText
  501. // --------------------------------------------------
  502.  
  503. void
  504. CTouchMeDialog::SetEdifFieldText(
  505.     PaneIDT        inPane,
  506.     const Str255    inString )
  507. {
  508.     ((CDateEditField *) FindPaneByID( inPane ))->SetText( inString );
  509. }
  510.  
  511.  
  512. // --------------------------------------------------
  513. //        ・ GetEdifFieldText
  514. // --------------------------------------------------
  515.  
  516. void
  517. CTouchMeDialog::GetEdifFieldText(
  518.     PaneIDT        inPane,
  519.     Str255        outString )
  520. {
  521.     ((CDateEditField *) FindPaneByID( inPane ))->GetText( outString );
  522. }
  523.  
  524.  
  525. // --------------------------------------------------
  526. //        ・ SetEdifFieldDateTime
  527. // --------------------------------------------------
  528.  
  529. void
  530. CTouchMeDialog::SetEdifFieldDateTime(
  531.     PaneIDT            inPane,
  532.     const unsigned long    inDateTimeSeconds )
  533. {
  534.     ((CDateEditField *) FindPaneByID( inPane ))->SetDateTime( inDateTimeSeconds );
  535. }
  536.  
  537.  
  538. // end of program
  539.